package view;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import model.GlobalParams;

public class MainFrame extends JFrame {	
	
	public MainFrame() {
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(new Dimension(GlobalParams.getInstance().DefautlXDimension,
								   GlobalParams.getInstance().DefaultYDimension));	
		setExtendedState(getExtendedState()|JFrame.MAXIMIZED_BOTH);
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {			
			e.printStackTrace();
		} catch (InstantiationException e) {			
			e.printStackTrace();
		} catch (IllegalAccessException e) {			
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {			
			e.printStackTrace();
		}
		setTitle("JCommander");	
		addComponents();	
		pack();
		setVisible(true);	
		
		
	} 
	
	private void addComponents() {
		
		panel = new JPanel();
		panel.setLayout(new BorderLayout());		
		
		southPanel = new JPanel();		
		southPanel_southPanel = new JPanel();
		
		menu = new MenuBar(this);
		hotKeysBar = new HotKeysBar(this);
		menuIconBar = new MenuIconBar(this);
		
		mainPanel  = new MainPanel(this);
		commandLineBar = new CommandLineBar();		
		
		setJMenuBar(menu);		
		panel.add(mainPanel, BorderLayout.CENTER);		
		panel.add(menuIconBar , BorderLayout.NORTH );
		panel.add(southPanel , BorderLayout.SOUTH);	
		
		
		BorderLayout border = new BorderLayout();
		border.setHgap(2);
		border.setVgap(2);
		southPanel.setLayout(border);
		
		southPanel.add(southPanel_southPanel, BorderLayout.SOUTH);		
	
		BorderLayout border1 = new BorderLayout();
		border1.setHgap(2);
		border1.setVgap(2);
		southPanel_southPanel.setLayout(border1);		
		southPanel_southPanel.add(hotKeysBar,BorderLayout.SOUTH);
		southPanel_southPanel.add(commandLineBar,BorderLayout.NORTH);		
		
		configure();
		
		panel.setVisible(true);	
		add(panel);			
	}	
	
	public void updateNames() {
		menu.updateNames();
		mainPanel.updateNames();
		hotKeysBar.updateNames();
		menuIconBar.updateNames();
	}
	
	public MainPanel getMainPanel() {
		return mainPanel;
	}
	
	public HotKeysBar getHotKeysBar() {		
		return hotKeysBar;
	}
	
	public CommandLineBar getCommandLineBar() {
		return commandLineBar;		
	}
	
	public void configure() {
		mainPanel.getPrimary().setActualPartitonToCommandLine();
	}	
	
	private JPanel panel;	
	private JPanel southPanel;	
	private JPanel southPanel_southPanel;	
	private MenuBar menu;
	private HotKeysBar hotKeysBar;
	private MainPanel mainPanel;
	private MenuIconBar menuIconBar;	
	private CommandLineBar commandLineBar;	
	private static final long serialVersionUID = 1L;
	
}
